package lab03.test09;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class Client {
    public static void main(String[] args) {

        List<Book> books = new ArrayList<Book>();
        String path = "E:\\book.txt";
        String path1 = "E:\\book1.txt";


        try {
            BufferedReader reader = new BufferedReader(new FileReader(path));
            String line =null;
            while ((line = reader.readLine()) != null) {
                String[] tokens = line.split("\t");
                Book book = new Book();
                book.booknum = Integer.parseInt(tokens[0].substring(tokens[0].length()-4,tokens[0].length()));
                book.bookname = tokens[1];
                book.version = tokens[2];
                book.price = Double.parseDouble(tokens[3]);
                book.sales = Double.parseDouble(tokens[4]);

                books.add(book);

            }

            int i = 1;

            for (Book b : books) {
                if (i == 3) {
                    b.price = b.price + 20;
                }
                if (i == 4) {
                    b.price = b.price + 30;
                }
            }

            BufferedWriter writer = new BufferedWriter(new FileWriter(path1));
            for (Book b : books) {
                writer.write(b.bookname + "" + b.version + "" + b.price + "" + b.sales);

            }
            writer.close();
            reader.close();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();

        }
    }
}
